<template>
  <div class="content">
    <nut-navbar class="navbar" z-index="5" :clickable="false" fixed safe-area-inset-top>
      <template #content>
        <span>{{ t(String(route.meta.title)) }}</span>
      </template>
      <template #left>
        <img src="/imgs/club/arrow_left.png" alt="" @click="router.go(-1)" class="arrow_left" />
      </template>
      <template #right>
        <span @click="router.push('/club')" class="save">{{ t('club_page_add') }}</span>
      </template>
    </nut-navbar>

    <!-- 我创建的俱乐部 -->
    <h2 class="my_club_title">{{ t('club_page_mycjjlb') }}</h2>
    <div class="club_list_box">
        <div class="club_list">
          <div v-for="club in createdClubList" :key="club.id" @click="enterClub(club.club_id)" class="club_card">
            <ClubItem :item="club" :isTables="false" />
          </div>
        </div>
    </div>
    <!-- 我加入的俱乐部 -->
    <h2 class="my_club_title">{{ t('club_page_mjrdjlb') }}</h2>
    <div class="club_list_box">
      <div class="club_list">
        <div v-for="club in joinedClubList" :key="club.id" @click="enterClub(club.club_id)" class="club_card">
          <ClubItem :item="club" :isTables="true" />
        </div>
      </div>
    </div>

    <!-- 悬浮框 -->
    <!-- <LevitateBox
      @checkGame="onGameClick"
      @miniClick="onSwitchGameClick"
    /> -->
  </div>
</template>
  
<script setup lang="ts">
import { useI18n } from "vue-i18n";
import { ref, onMounted, onUnmounted } from "vue";
import {useRoute, useRouter} from "vue-router";

import ClubItem from "@/components/ClubItem.vue";
  
import PKwebsocket from "@/lolo/Ws";
import { NetPacket } from "@/netBase/NetPacket";


const route = useRoute();
const router = useRouter();
const { t } = useI18n();

const createdClubList: any = ref([])
const joinedClubList: any = ref([])

// 获取俱乐部列表
const getClubList = () => {
  const req = NetPacket.req_get_club_list();
  PKwebsocket.instance.send(req, true, {
    callbackName: "msg_notify_get_club_list",
    callback: getClubListHandle,
  });
};
// 俱乐部列表返回
const getClubListHandle = (res: any) => {
  createdClubList.value = res.created_club_list
  joinedClubList.value = res.joined_club_list
};


const enterClub = (id: number) => {
  router.push({
    path: "/club/detail",
    query: {
      club_id: id,
    },
  });
}

// const onGameClick = (item: any) => {
//   console.log("Selected game:", item.label);
// }

// const onSwitchGameClick = (game: { id: number; title: string }) => {
//   console.log(`你点击了游戏：${game.title}`);
//  }

onUnmounted(() => {
  // 取消监听
});

onMounted(() => {
  getClubList();
});
</script>
  
<style scoped lang="scss">
  .content {
    font-size: 14px;
    margin: 0 0 10px;

    .arrow_left {
      width: 24px;
      height: 24px;
    }
    :deep(.nut-navbar__right,.nut-navbar__left) {
      padding: 0;
    }
    .save {
      width: 56px;
      height: 32px;
      line-height: 32px;
      text-align: center;
      color: #FFFFFF;
      background: linear-gradient(180deg, #5567FF 0%, #9E1EFF 100%);
      box-shadow: 0.5px 0.5px 1px 0px #9B9EFF inset;
      border-radius: 8px;
    }
    .game_title {
      margin: 40px 0 12px 14px;
      img {
        width: 24px;
        height: 24px;
        display: inline-block;
        vertical-align: top;
      }
      span {
        color: #FFF;
        text-align: center;
        font-family: "PingFang SC";
        font-size: 16px;
        font-weight: 600;
      }
    }
    
    :deep(.nut-popup) {
      background: #131232B2;
    }
    
    .my_club_title {
      width: 347px;
      margin: 16px auto 8px;
      color: #FFFFFF;
      font-size: 14px;
      text-align: left;
    }

    .club_list_box {
      padding-left: 14px;

      .card_title {
        display: flex;
        padding: 0 14px;
        justify-content: space-between;
        align-items: center;
        height: 24px;
        line-height: 24px;
        margin: 12px 0;

        .title_left {
          font-family: PingFang SC;
          font-size: 14px;
          font-weight: 600;
          line-height: 16px;
          text-align: left;
          color: #FCFFFA;
          display: flex;
          justify-content: space-between;
          align-items: center;

          img {
            width: 18px;
            height: 18px;
            margin-right: 5px;
          }
        }

        .title_right {
          font-family: PingFang SC;
          font-size: 12px;
          font-weight: 500;
          color: #C6C4F5;
          display: flex;
          justify-content: space-between;
          align-items: center;
          height: 24px;

          .more {
            background: #282747;
            // margin-left: 8px;
            // height: 100%;
            line-height: 25px;
            padding: 0px 8px;
            border-radius: 6px;
            box-shadow: 0.5px 0.5px 1px 0px #4B4A6E inset;
          }

          .swiper-btn {
            position: relative;
            top: 4px;
            margin-left: 8px;
          }

          .disabled {
            pointer-events: none;
            opacity: 0.5;
            cursor: not-allowed;
          }
        }
      }

      .club_list {
        display: flex;
        flex-direction: column;
        gap: 10px;

        .club_card {
          width: 347px;
          height: 60px;
          display: flex;
          align-items: center;
          justify-content: space-around;
          border-radius: 10px;
          padding: 10px;
          color: white;
          background: url(/imgs/club/add_club_bg.png) no-repeat;
          background-size: 100% 100%;

          .club_icon {
            position: relative;
            width: 48px;
            height: 48px;
            margin-right: 8px;
            // overflow: hidden;

            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
              object-fit: cover;
            }

            .badge {
              width: 48px;
              position: absolute;
              bottom: -5px;
              right: -5px;
              border-radius: 0 0 8px 8px;
              font-size: 12px;
              text-align: center;
              color: white;
              background: rgba(0, 0, 0, 0.6);
            }
          }
          .club_info {
            flex: 1;
            overflow: hidden;

            .club_name {
              font-size: 14px;
              font-weight: bold;
              margin: 0;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
            }

            .club_id,
            .club_desc {
              width: 190px;
              font-size: 12px;
              margin: 2px 0 0;
              font-family: PingFang SC;
              color: #AFB6BD;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
            }
          }
          .club_action {
            display: flex;
            align-items: center;

            .club_btn {
              width: 40px;
              height: 20px;
              color: white;
              border: none;
              border-radius: 5px;
              font-size: 12px;
              line-height: 20px;
              text-align: center;
              background: #1DBA8B;
            }

            .arrow {
              width: 16px;
              height: 16px;
              margin-left: 10px;
              font-size: 18px;
              color: #FFFFFF;
            }
          }
        }
      }
    }

    .levitate_box {
      width: 72px;
      min-height: 72px;
      position: fixed;
      right: 15px;
      bottom: 86px;
      z-index: 99;
      li {
        margin: 6px 0;

        img {
          width: 72px;
          height: 72px;
        }
      }
      
    }
  }
</style>
  